﻿Public Class frmImage

    Public Enum enumFormat
        Metafile
        Bitmap
        File
    End Enum

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        SaveSetting(REGAPP, "SendToImage", "Format", cboFormat.SelectedIndex)
        SaveSetting(REGAPP, "SendToImage", "Resize", chkResize.Checked)
        SaveSetting(REGAPP, "SendToImage", "Resolution", txtResolution.Text)
        SaveSetting(REGAPP, "SendToImage", "Width", txtWidth.Text)
        SaveSetting(REGAPP, "SendToImage", "Height", txtHeight.Text)
        SaveSetting(REGAPP, "SendToImage", "AllGraphs", chkAllGraphs.Checked)
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub frmClipboard_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        cboFormat.Items.Add("Clipboard (Metafile)")
        cboFormat.Items.Add("Clipboard (Bitmap)")
        cboFormat.Items.Add("Graphic File (will prompt for filename)")
        cboFormat.SelectedIndex = GetSetting(REGAPP, "SendToImage", "Format", 0)
        chkResize.Checked = GetSetting(REGAPP, "SendToImage", "Resize", False)
        txtResolution.Text = GetSetting(REGAPP, "SendToImage", "Resolution", 300)
        txtWidth.Text = GetSetting(REGAPP, "SendToImage", "Width", 6.5)
        txtHeight.Text = GetSetting(REGAPP, "SendToImage", "Height", 4)
        chkAllGraphs.Checked = ApplyToAllTabs Or GetSetting(REGAPP, "SendToImage", "AllGraphs", False)
        FillLayoutList()
    End Sub

    Private Sub FillLayoutList()
        With cboLayout
            .Items.Clear()
            .Items.Add("(Single image per graph)")
            .Items.Add("(Display Page Setup dialog)")
            For Each s As String In Layouts.Keys
                .Items.Add(s)
            Next
            If .Items.Contains(GraphForm.ActiveLayoutName) Then .Text = GraphForm.ActiveLayoutName Else .SelectedIndex = 0
        End With
    End Sub

    Private Sub txtWidth_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtWidth.Validating, txtResolution.Validating
        If Val(txtWidth.Text) = 0 Then
            WarningMsg("You must enter a non-zero numeric value for the width.")
            e.Cancel = True
        End If
    End Sub

    Private Sub chkResize_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkResize.CheckedChanged
        grpResize.Enabled = chkResize.Checked
    End Sub

    Private Sub cboLayout_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles cboLayout.SelectedIndexChanged
        If cboLayout.Text.StartsWith("(Display") Then
            With New frmLayout
                .DefaultLayoutName = GraphForm.ActiveLayoutName
                .chkHide.Visible = True
                .grpOrientation.Enabled = False
                .txtBottom.Enabled = False
                .txtLeft.Enabled = False
                .txtRight.Enabled = False
                .txtTop.Enabled = False
                .ShowDialog(Me)
                cboLayout.Text = .cboLayout.Text
                .Dispose()
            End With
            FillLayoutList()
        End If
    End Sub

End Class
